﻿using System;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using gms.security;

namespace gms.data {
	public class Player : IComparable {
#region Properties
		public int player_id { get; set; }
		public string first_name { get; set; }
		public string last_name { get; set; }
		public string email { get; set; }
		public byte[] password { get; set; }
		public byte[] salt { get; set; }
		public string address { get; set; }
#endregion
#region Constructors

#endregion
#region Additional Loads

#endregion
#region CRUD
		public static void create(string fname, string lname, string mail, string pass) {
			//byte[] new_salt = pcdb.security.password.generate_salt();
			//byte[] new_pass = pcdb.security.password.get_password_hash(pass, new_salt);

			//SqlParameter[] parm = new SqlParameter[6];
			//parm[0] = new SqlParameter("@first_name", fname);
			//parm[1] = new SqlParameter("@last_name", lname);
			//parm[2] = new SqlParameter("@email", mail);
			//parm[3] = new SqlParameter("@password", new_pass);
			//parm[4] = new SqlParameter("@salt", new_salt);
			//parm[5] = new SqlParameter("@address", HttpContext.Current.Request.UserHostAddress);

			//database.exec_anon("dbo.pr_player_new", parm);
		}
		public void update_password(string pass) {
			/*
			byte[] new_pass = pcdb.security.password.get_password_hash(pass, salt);

			SqlParameter[] parm = new SqlParameter[2];
			parm[0] = new SqlParameter("@player_id", player_id);
			parm[1] = new SqlParameter("@password", new_pass);

			this.execute("dbo.pr_player_change_password", parm);
			*/
		}
#endregion
#region Utilities
		public int CompareTo(object obj) {
			//player comp = (player)obj;

			//if (first_name != comp.first_name) {
			//    return first_name.CompareTo(comp.first_name);
			//}
			//else {
			//    return last_name.CompareTo(comp.last_name);
			//}

			return 0;
		}
		private void fill(DataSet values) {
			if (!Database.dataset_is_empty(values)) {
				for (int i = 0; i < values.Tables[0].Columns.Count; i++) {
					switch (values.Tables[0].Columns[i].ColumnName) {
						case "player_id": player_id = (int)values.Tables[0].Rows[0]["player_id"]; break;
						case "first_name": first_name = (string)values.Tables[0].Rows[0]["first_name"]; break;
						case "last_name": last_name = (values.Tables[0].Rows[0]["last_name"] != DBNull.Value) ? (string)values.Tables[0].Rows[0]["last_name"] : null; break;
						case "email": email = (string)values.Tables[0].Rows[0]["email"]; break;
						case "password": password = (byte[])values.Tables[0].Rows[0]["password"]; break;
						case "salt": salt = (byte[])values.Tables[0].Rows[0]["salt"]; break;
						case "address": address = (string)values.Tables[0].Rows[0]["address"]; break;
					}
				}
			}
		}
#endregion
	}
}